﻿using System;
using System.Windows.Forms;
using ApplicationGenerator.Forms.WebControls;


namespace ApplicationGenerator.Forms.Utilities
{
    /// <summary>
    /// Factory for Designer Controls. Recognision by Type 
    /// </summary>
    public class BLogicControlFactory
    {
        #region Variables

        private static volatile BLogicControlFactory instance;
        private static object syncObj = new Object();

        #endregion

        #region Constructors

        //just private constructor
        private BLogicControlFactory()
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// for getting instance of factory
        /// </summary>
        public static BLogicControlFactory Instance
        {
            get
            {
                if (null == instance)
                {
                    lock (syncObj)
                    {
                        if (null == instance)
                        {
                            instance = new BLogicControlFactory();
                        }
                    }
                }

                return instance;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// produces new standard control.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public BaseControl GetLogicControl(Type type)
        {
            if (typeof(TextBox) == type)
            {
                return new TextBoxControl();
            }
            else if (typeof(Label) == type)
            {
                return new LabelControl();
            }
            else if (typeof(CheckBox) == type)
            {
                return new CheckBoxControl();
            }
            else if (typeof(ComboBox) == type)
            {
                return new DropDownListControl();
            }
            else if (typeof(Button) == type)
            {
                return new ButtonControl();
            }
            else if (typeof(LinkLabel) == type)
            {
                return new SetRelationControl();
            }
            else if (typeof(ListBox) == type)
            {
                return new DisplayListControl();
            }
            else if (typeof(ListView) == type)
            {
                return new SetListControl();
            }
            else if (typeof(ButtonControl) == type)
            {
                return new ButtonControl();
            }
            return null;
        }

        #endregion
    }
}
